package com.cloudcc.cloudframe.bus;

import de.greenrobot.event.EventBus;

public class EventEngine {

	/**
	 * 将事件添加到bus总线中
	 * 
	 * @param event
	 */
	public static void post(Object event) {
		EventBus.getDefault().post(event);
	}

	/**
	 * 注册 订阅 总线上的 指定时间
	 * 
	 * @param subscriber
	 */
	public static void register(Object subscriber) {
		if (subscriber != null && (!isRegisted(subscriber))) {
			EventBus.getDefault().register(subscriber);
		}
	}

	/**
	 * 取消订阅 总线上的事件
	 * 
	 * @param subscriber
	 */
	public static void uregister(Object subscriber) {
		EventBus.getDefault().unregister(subscriber);
	}

	/**
	 * 取消事件的传递
	 * 
	 * @param event
	 */
	public static void cancel(Object event) {
		EventBus.getDefault().cancelEventDelivery(event);
	}

	/**
	 * 是否已经注册
	 * 
	 * @param subscriber
	 * @return
	 */
	public static boolean isRegisted(Object subscriber) {
		return EventBus.getDefault().isRegistered(subscriber);
	}
}
